package com.hboxs.asl.controller.app.member;

import com.hboxs.asl.JsonMessage;
import com.hboxs.asl.controller.app.BaseController;
import com.hboxs.asl.entity.EnterpriseService;
import com.hboxs.asl.entity.Member;
import com.hboxs.asl.service.EnterpriseServiceService;
import com.hboxs.asl.service.MemberService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by xxx on 2016/12/16
 */
@Controller(value = "appMemberEnterpriseServiceController")
@RequestMapping(value = "/app/m/enterpriseService")
public class EnterpriseServiceControl extends BaseController {

    @Resource(name = "memberServiceImpl")
    private MemberService memberService;
    @Resource(name = "enterpriseServiceServiceImpl")
    private EnterpriseServiceService enterpriseServiceService;

    /**
     * 提交企业服务
     *
     * @param enterpriseService 企业服务
     * @return 企业服务
     */
    @RequestMapping(value = "/submit", method = RequestMethod.POST)
    public
    @ResponseBody
    Object submit(EnterpriseService enterpriseService) {

        try {
            Member member = memberService.getCurrentByToken();
            if (member == null) {
                return JsonMessage.USER_NOT_LOGIN;
            }
            if (enterpriseService.getName() == null) {
                return JsonMessage.error("公司名不能为空");
            }
            if (enterpriseService.getAddress() == null) {
                return JsonMessage.error("地址不能为空");
            }
            if (enterpriseService.getPhone() == null) {
                return JsonMessage.error("联系电话不能为空");
            }
            if (enterpriseService.getAttn() == null) {
                return JsonMessage.error("联系人不能为空");
            }
            if (enterpriseService.getIntention() == null) {
                return JsonMessage.error("合作意向不能为空");
            }
            enterpriseService.setMember(member);
            enterpriseServiceService.save(enterpriseService);
            return JsonMessage.success();

        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return JsonMessage.UNKNOWN_ERROR;
    }

}
